package com.kyh.service.impl;

import com.kyh.properties.QiniuProps;
import com.kyh.service.UploadService;
import com.kyh.vo.R;
import com.qiniu.util.Auth;
import com.alibaba.fastjson.JSONObject;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("uploadService")
public class UploadServiceImpl implements UploadService {

    @Override
    @Transactional
    public R getQiniuToken() {
    	
    	String accessKey = QiniuProps.get("accesskey");
    	String secretKey = QiniuProps.get("secretkey");
    	String bucketName = QiniuProps.get("bucketname");
    	String domain = QiniuProps.get("domain");
        String authtoken = Auth.create(accessKey, secretKey).uploadToken(bucketName);
        JSONObject re = new JSONObject();
        re.put("authtoken", authtoken);
        re.put("domain", domain);
        return R.ok(re);
    }
}
